package com.zbkj.crmeb.merchant.admin.controller;


import com.crmeb.core.common.CommonResult;
import com.zbkj.crmeb.chant.model.ChannelMemberLevel;
import com.zbkj.crmeb.chant.request.MemberLevelRequest;
import com.zbkj.crmeb.chant.service.ChannelMemberLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 * 商户会员等级表 前端控制器
 * </p>
 *
 * @author wuzp
 * @since 2022-06-13
 */
@RestController
@RequestMapping("/api/admin/mer/level/member")
@Api(tags = "商户后台-等级会员")
public class MerChannelMemberLevelController extends AdminBaseController{

    @Autowired
    private ChannelMemberLevelService channelMemberLevelService;

    @ApiOperation(value = "编辑等级会员")
    @PutMapping(value = "/edit")
    public CommonResult<String> updateMemberLevel(@RequestBody @Validated MemberLevelRequest request, HttpServletRequest servletRequest){
        if(request.getPriceLadder() != 1 && request.getRatio() == null){
            return CommonResult.failed("请输入会员折扣");
        }
        request.setMerId(getMerId(servletRequest));
        return channelMemberLevelService.updateMemberLevel(request);
    }

    @ApiOperation(value = "编辑状态")
    @PutMapping(value = "/edit/status/{id}")
    public CommonResult<String> updateMemberLevelStatus(@PathVariable Integer id,@RequestParam(value = "status") Integer status, HttpServletRequest servletRequest){
        return channelMemberLevelService.updateMemberLevelStatus(id,status,getMerId(servletRequest));
    }

    @ApiOperation(value = "列表")
    @GetMapping(value = "/list")
    public CommonResult<List<ChannelMemberLevel>> getMemberLevelList(@ApiParam(value = "状态 0全部  1开启", required = true) Integer type ,HttpServletRequest servletRequest){
        return CommonResult.success(channelMemberLevelService.getMemberLevelList(type,getMerId(servletRequest),null));
    }

}

